package top.buyibuyi.course.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import top.buyibuyi.course.esayExcel.ExcelStuSchose;
import top.buyibuyi.course.exceptionHandler.GuliException;
import top.buyibuyi.course.pojo.StuSchose;
import top.buyibuyi.course.service.UploadFileService;

public class StuExcelListener extends AnalysisEventListener<ExcelStuSchose> {

    public UploadFileService uploadFileService;

    public StuExcelListener(UploadFileService uploadFileService) {
        this.uploadFileService = uploadFileService;
    }

    public StuExcelListener() {
    }

    @Override
    public void invoke(ExcelStuSchose stuSchose, AnalysisContext analysisContext) {
        if(stuSchose == null){
            throw new GuliException(20001,"文件数据为空");
        }
        StuSchose schose = new StuSchose();

        schose.setStuid(stuSchose.getStuid());
        schose.setSname(stuSchose.getSname());
        schose.setCollege(stuSchose.getCollege());
        schose.setNowresults(stuSchose.getNowresults());
        schose.setMidresults(stuSchose.getMidresults());
        schose.setFinalresults(stuSchose.getFinalresults());
        schose.setSkillresults(stuSchose.getSkillresults());
        schose.setTotalresults(stuSchose.getTotalresults());
        schose.setIspass(stuSchose.getIspass());
        schose.setChooseid(stuSchose.getChooseid());
        uploadFileService.save(schose);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
